package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 言初
 * Date: 2023-01-09
 * Time: 10:19
 */
public class ReturnOperation implements IOPeration{
    public void work (BookList bookList){
        System.out.println("归还图书");
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你要归还图书的书名：");
        String name=sc.nextLine();
        sc.close();

        //检查这本书是否在书架中，是否被借出
        int currentSize=bookList.getUsedSize();
        for(int i=0;i<currentSize;i++){
            Book tmp=bookList.getBook(i);
            if(tmp.getName().equals(name) && tmp.isBorrowed()==true){
                tmp.setBorrowed(false);
                System.out.println("归还成功");
                return;
            }
        }
        System.out.println("归还失败");
    }
}
